﻿using System;
using System.Collections.Generic;
using GeoAPI.Geometries;
using NetTopologySuite.Noding;

namespace NetTopologySuite.Geometries.Prepared
{
	internal class PreparedPolygonContainsProperly : PreparedPolygonPredicate
	{
		public static bool ContainsProperly(PreparedPolygon prep, IGeometry geom)
		{
			return new PreparedPolygonContainsProperly(prep).ContainsProperly(geom);
		}

		public PreparedPolygonContainsProperly(PreparedPolygon prepPoly) : base(prepPoly)
		{
		}

		public bool ContainsProperly(IGeometry geom)
		{
			if (!base.IsAllTestComponentsInTargetInterior(geom))
			{
				return false;
			}
			IList<ISegmentString> segStrings = SegmentStringUtil.ExtractSegmentStrings(geom);
			return !this.prepPoly.IntersectionFinder.Intersects(segStrings) && (!(geom is IPolygonal) || !base.IsAnyTargetComponentInAreaTest(geom, this.prepPoly.RepresentativePoints));
		}
	}
}
